#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "calc.h"

int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf("Usage: %s expression\n", argv[0]);
        printf("Example: %s 17+2 or %s 8*9\n", argv[0], argv[0]);
        return 1;
    }

    char *expression = argv[1];
    int a, b;
    char operator;
    int result;

    if (sscanf(expression, "%d%c%d", &a, &operator, &b) != 3) {
        printf("Error: Invalid expression format\n");
        return 1;
    }

    switch (operator) {
        case '+':
            result = add(a, b);
            break;
        case '-':
            result = subtract(a, b);
            break;
        case '*':
            result = multiply(a, b);
            break;
        case '/':
            if (b == 0) {
                printf("Error: Division by zero\n");
                return 1;
            }
            result = divide(a, b);
            break;
        default:
            printf("Error: Unsupported operator '%c'\n", operator);
            printf("Supported operators: +, -, *, /\n");
            return 1;
    }

    printf("%d%c%d = %d\n", a, operator, b, result);
    return 0;
}
